// by Xeno
//#define __DEBUG__
#define THIS_FILE "x_marker.sqf"
#include "x_setup.sqf"

GVAR(mark_loc280) = localize "STR_DOM_MISSIONSTRING_280";

#ifndef __TT__
if (GVAR(dont_show_player_markers_at_all) == 1) then {
	// TYRGHEN - Failsafe
	if (isNil QGVAR(p_marker) || {GVAR(p_marker) == ""}) then {	GVAR(p_marker) = "mil_dot"; };
	__TRACE_1(QGVAR(p_marker),QGVAR(p_marker))
	{[_x, [0,0],"ICON","ColorGreen",[0.7,0.7],"",0,GVAR(p_marker)] call FUNC(CreateMarkerLocal)} forEach GVAR(player_entities);
};
#endif

#ifdef __TT__
_cservicename = QGVAR(chopper_service);
_wrepname = QGVAR(wreck_service);
_telename = QGVAR(teleporter);
_jetservicename = QGVAR(aircraft_service);
_bonusairname = "bonus_air";
_bonusvecname = "bonus_vehicles";
_ammoload = "Ammobox Reload";
_vec_serv = QGVAR(vehicle_service);
_start_marker = "Start";
if (GVAR(player_side) == opfor) then {
	_cservicename = QGVAR(chopper_serviceR);
	_wrepname = QGVAR(wreck_serviceR);
	_telename = QGVAR(teleporter_1);
	_jetservicename = QGVAR(aircraft_serviceR);
	_bonusairname = "bonus_airR";
	_bonusvecname = "bonus_vehiclesR";
	_ammoload = "Ammobox ReloadR";
	_start_marker = "Start_opfor";
	_vec_serv = QGVAR(vehicle_serviceR);
};
{
	_x setMarkerAlphaLocal 1;
} forEach [_cservicename,_wrepname,_telename,_jetservicename,_bonusairname,_bonusvecname,_ammoload,_vec_serv,_start_marker];

GVAR(entities_tt) = if (GVAR(player_side) == blufor) then {
	GVAR(entities_tt_blufor)
} else {
	GVAR(entities_tt_opfor)
};

if (GVAR(dont_show_player_markers_at_all) == 1) then {
	{[_x, [0,0],"ICON","ColorGreen",[0.7,0.7],"",0,GVAR(p_marker)] call FUNC(CreateMarkerLocal)} forEach GVAR(entities_tt);
};
#endif

if (GVAR(with_ai)) then {
	for "_ai" from 2 to 40 do {
		[format ["AI_X%1%2", GVAR(string_player), _ai], [0,0],"ICON","ColorGreen",[0.7,0.7],"",0,GVAR(p_marker)] call FUNC(CreateMarkerLocal);
	};
};

0 spawn {
	scriptName "spawn_start_marker";
	sleep 10;
	// TYRGHEN - Added Tao Foldmap check for markers redrawing
	["marker_vecs", {if (visibleMap || {GVAR(do_ma_update_n)} || {!isNil {uiNamespace getVariable "BIS_RscMiniMap"}} || {!isNil {uiNamespace getVariable "RscMiniMapSmall"}} || {!isNil {uiNamespace getVariable "Tao_FoldMap"}}) then {call FUNC(X_XMarkerVehicles)}}, 0] call FUNC(addPerFrame);
	["marker_units", {
		// TYRGHEN - Added Tao Foldmap check for markers redrawing
		if (GVAR(show_player_marker) > 0 && {visibleMap || {GVAR(do_ma_update_n)} || {!isNil {uiNamespace getVariable "BIS_RscMiniMap"}} || {!isNil {uiNamespace getVariable "RscMiniMapSmall"}} || {!isNil {uiNamespace getVariable "Tao_FoldMap"}}}) then {
			call FUNC(X_XMarkerPlayers);
			if (GVAR(with_ai)) then {
				call FUNC(X_XAI_Markers);
			};
		};
	}, 0] call FUNC(addPerFrame);
};